package com.mgface.completableFuture;

import java.nio.file.attribute.FileTime;
import java.sql.Timestamp;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class DateTimeFormatterDemo {
	public static void syso(Object obj) {
		System.out.println(obj);
	}

	public static void main(String[] args) throws Throwable {
		syso(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(LocalDateTime.now()));
		syso(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()));
		syso(DateTimeFormatter.ISO_ZONED_DATE_TIME.format(ZonedDateTime.now()));
		syso(DateTimeFormatter.ISO_INSTANT.format(ZonedDateTime.now()));
		syso(DateTimeFormatter.ISO_ORDINAL_DATE.format(LocalDateTime.now()));
		syso(DateTimeFormatter.ISO_WEEK_DATE.format(LocalDateTime.now()));
		syso(DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now()));
		
		DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
		syso(dtf.format(LocalDateTime.now()));
		DateTimeFormatter dtf3 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
		syso(dtf3.format(LocalDateTime.now()));
		DateTimeFormatter dtf4 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
		syso(dtf4.format(LocalDateTime.now()));
		DateTimeFormatter dtf2 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL);
		syso(dtf2.format(ZonedDateTime.now()));
		
		DateTimeFormatter dtf5 = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withLocale(Locale.TAIWAN);
		syso(dtf5.format(LocalDateTime.now()));
		DateTimeFormatter dtf6 = DateTimeFormatter.ofPattern("G MMM e K a yyyy-MM-dd HH:mm:ss SSS",Locale.CHINA);
		syso(dtf6.format(ZonedDateTime.now()));
		syso(dtf6.format(LocalDateTime.now()));
		
		Date date = new Date();
		Instant instant = date.toInstant();//把日期转换成instant
		syso(instant);
		Date d = Date.from(instant);//把instant转换成日期
		syso(d);
		Timestamp tt = Timestamp.from(instant);
		syso(tt);
		instant = tt.toInstant();
		syso(instant);
		LocalDateTime ldt = tt.toLocalDateTime();
		syso(ldt);
		
		LocalDate ld = LocalDate.now();
		syso(ld);
		java.sql.Date date2 = java.sql.Date.valueOf(ld);//把localdate转成Date
		syso(date2);
		syso(date2.toLocalDate());
		TimeZone tz= TimeZone.getTimeZone("Asia/Shanghai");
		syso(tz);
		ZoneId zi = tz.toZoneId();
		syso(zi);
		
		FileTime ft = FileTime.from(instant);
		syso(ft);
		instant = ft.toInstant();
		syso(instant);
	}
	

}
